package com.haozi.ehub.core.handler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

/**
 * @author     ： terry
 * @date       ： Created in 2020/6/19 15:44
 */
@MappedTypes(value={Object.class})
@MappedJdbcTypes(JdbcType.OTHER)
@SuppressWarnings(value = "all")
public class MybatisTypeHandler extends BaseTypeHandler<Object>{

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
			throws SQLException {
		ps.setString(1, String.valueOf(parameter.toString()));
		
	}

	@Override
	public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
		if(columnName!=null){
			return rs.getString(columnName);
		}
		return null;
	}

	@Override
	public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return null;
	}

	@Override
	public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		return null;
	}

}
